package com.ttg.web.juc;



import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.concurrent.Callable;


/**
 * @Time 2023/2/17 11:11
 * @Version 1.0.0
 * @Author liujie
 * @Destination
 */
@Slf4j
@Data
public class ListenableFutureTaskTemp<P> implements Callable<Object> {
    private  volatile Boolean isSkip=false;
    private  String msg;//错误原因通知
    private Object resut;//业务返回结果
    private  P[] p;//参数
    TargetWarpper targetWarpper;
    public ListenableFutureTaskTemp(TargetWarpper targetWarpper,P... p ) {
        this.p=p;
       this.targetWarpper=targetWarpper;
    }

    @Override
    public Object call() throws Exception {
        try{
            if(!targetWarpper.getIsEnable()){
                resut="包装对象初始化失败请查看具体原因";
                return   resut;
            }
            Method method=targetWarpper.getMethod();
            if(method.getReturnType().getName().equals("void")){
                method.invoke(targetWarpper.getT(),p);
                resut="执行成功";
            }else {
                resut = method.invoke(targetWarpper.getT(),p);
            }
        }catch (Exception e){
            log.error("ListenableFutureTask异步通知错误："+e.getMessage());
            resut="执行失败,具体原因请看msg";
             msg=e.getMessage();
        }finally {
            return  resut;
        }
    }
}
 